package com.lingo.a2b.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.lingo.a2b.common.util.TranslateUtils;
import com.lingo.a2b.common.util.model.ClassFieldTree;
import com.lingo.a2b.service.TranslateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

/**
 * @author lingo
 * @date 2020/5/21 15:52
 * @Company: www.xyb2b.com
 */
@Service
public class TranslateServiceImpl implements TranslateService {
    private static Logger logger = LoggerFactory.getLogger(TranslateServiceImpl.class);

    @Autowired
    private TranslateUtils translateUtils;


    @Override
    public JSONObject translate(Object data, int fprojectId) {
        ClassFieldTree classFieldTree = translateUtils.projectToTree(fprojectId);
        return translateUtils.extractTree(classFieldTree,data);
    }


    @Override
    public boolean isClassExist(String name) {
        return ClassUtils.isPresent(name,this.getClass().getClassLoader());
    }
}
